<?php


namespace App\Services\pay;


use App\Models\Order;
use App\Models\RentAndPurchase;
use App\Services\HouseServices;
use App\Services\OrderService;
use function Composer\Autoload\includeFile;

class PayServer
{
    /**
     * @Notes:判断类型
     * @Author:Planb,
     * @Date: 2022/11/12,
     * @Time: 10:17,
     */
    public function payType($type,$uid,$houseId){
        switch ($type){
            case 1:
                    $orderInfo = OrderService::getOrderInfo($uid,$houseId);
                    $houseAuditInfo = HouseServices::getHouseAuditInfo($houseId);
                    if($orderInfo && $houseAuditInfo){
                        (new AliPayType())->pay($orderInfo['order_sn'], $houseAuditInfo['house_name'], $orderInfo['pay_price'], $houseAuditInfo['house_title']);
                    }else{
                        return false;
                    }
             break;

            case 2:
                   $orderInfo = OrderService::getOrderInfo($uid,$houseId);
                   $houseAuditInfo = HouseServices::getHouseAuditInfo($houseId);
                   if($orderInfo && $houseAuditInfo){
                       (new AliPayType())->pay($orderInfo['order_sn'], $houseAuditInfo['house_name'], $orderInfo['pay_price'], $houseAuditInfo['house_title']);
                   }else{
                    return false;
                    }

             break;

            case 3:

                $orderInfo = OrderService::getOrderInfo($uid,$houseId);

                $rentAnd = RentAndPurchase::where('uid',$uid)->where('id',$houseId)->first();
                if($rentAnd&&$orderInfo){
                    (new AliPayType())->pay($orderInfo['order_sn'], $rentAnd['house_name']==""?rand(1,9999999):$rentAnd['house_name'], $orderInfo['pay_price'], $rentAnd['house_title']);
                }else{
                    return false;
                }
                break;

        }
    }
}
